package edu.zut.filter;

import javax.servlet.*;
import java.io.IOException;

public class DemoFilter1 implements Filter {

    /**
     * 生命周期：初始化，只会在创建当前filter对象时执行
     * @param filterConfig 当前过滤器的配置信息
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("filter1初始化.........");
    }

    /**
     * 生命周期：执行
     * @param request 表示拦截的请求
     * @param response 表示拦截的响应
     * @param chain 过滤器链 过滤器可能会有多个，此时会形成一个链
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("filter1的过滤执行逻辑");
        //资源的放行
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {
        System.out.println("filter1的销毁");
    }
}
